package com.gt.xmall.web;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.gt.xmall.model.GtdContext;
import com.gt.xmall.service.GtdContextService;
import com.gt.xmall.web.BaseController;

import com.gt.xmall.model.GtdCollection;
import com.gt.xmall.service.GtdCollectionService;

@Controller
@RequestMapping(value = "/gtd/gtdcollection/")
public class GtdCollectionController extends BaseController {
	
	@Autowired
	private GtdCollectionService gtdCollectionService;
	
	@RequestMapping(value = "list",method = RequestMethod.GET)
	public String list(Model model){
		List<GtdCollection> list = gtdCollectionService.getGtdCollections();
		model.addAttribute("gtdCollectionList", list);
		return "gtd/gtdCollectionList";
	}
	@RequestMapping(value = "show/{id}",method = RequestMethod.GET)
	public String show(@PathVariable("id") String id,Model model){
		GtdCollection gtdCollection =gtdCollectionService.getGtdCollection(new Long(id));
		model.addAttribute("gtdCollection", gtdCollection);
		return "gtd/gtdCollectionForm";
		
	}
	@RequestMapping(value="save",method = RequestMethod.POST)
	public String save(@Valid GtdCollection gtdCollection,RedirectAttributes redirectAttributes){
		gtdCollection = gtdCollectionService.saveGtdCollection(gtdCollection);
//		redirectAttributes.addAttribute("gtdContext", gtdContext);
		return "redirect:/gtd/gtdcollection/show/"+gtdCollection.getId();
	} 
	@RequestMapping(value = "new",method = RequestMethod.GET)
	public String blankForm(){
		return "gtd/gtdCollectionForm";
	}
	
	@RequestMapping(value = "delete/{id}",method = RequestMethod.GET)
	public String delete(@PathVariable("id") String id,Model model){
		gtdCollectionService.deleteGtdCollection(new Long(id));
		
		return "redirect:/gtd/gtdcollection/list";
		
	}
	
}